import { request } from "@umijs/max";

// /system/role/list
export async function getRoleList(
  params: {
    // query
    /** 当前的页码 */
    pageNum?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any }
) {
  return request<API.RoleList>("/api/system/role/list", {
    method: "GET",
    params: {
      ...params,
    },
    ...(options || {}),
  });
}
// PUT  /system/role

export async function updateRole(
  data: API.RoleForm,
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/role", {
    method: "PUT",
    data,
    ...(options || {}),
  });
}

// POST /system/role
export async function addRole(
  data: API.RoleForm,
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/role", {
    method: "POST",
    data,
    ...(options || {}),
  });
}
// /system/menu/roleMenuTreeselect/101
export async function getRoleMenuTreeSelect(
  roleId: number | string,
  options?: { [key: string]: any }
) {
  return request<API.MenuTreeSelect>(
    "/api/system/menu/roleMenuTreeselect/" + roleId,
    {
      method: "GET",
      ...(options || {}),
    }
  );
}
// /system/role/101
export async function getRoleInfo(
  roleId: number | string,
  options?: { [key: string]: any }
) {
  return request<API.RoleForm>("/api/system/role/" + roleId, {
    method: "GET",
    ...(options || {}),
  });
}
//del /system/role/103
export async function delRole(
  roleId: number | string,
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/role/" + roleId, {
    method: "DELETE",
    ...(options || {}),
  });
}
// /system/role/changeStatus
export async function changeRoleStatus(
  data: { roleId: number | string; status: string },
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/role/changeStatus", {
    method: "PUT",
    data,
    ...(options || {}),
  });
}
// system/user/authRole
export async function authRole(
  userId: number | string,
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/user/authRole/" + userId, {
    method: "GET",
    ...(options || {}),
  });
}
// /system/user/authRole?userId=2&roleIds=2,101 PUT
export async function updateAuthRole(
  params: {
    userId: number | string;
    roleIds: string;
  },
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/user/authRole", {
    method: "PUT",
    params,
    ...(options || {}),
  });
}
// /system/role/authUser/cancel
export async function cancelAuthUser(
  data: { roleId: number | string; userId?: string },
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/role/authUser/cancel", {
    method: "PUT",

    data,
    ...(options || {}),
  });
}
export async function cancelAuthAllUser(
  data: { roleId: number | string; userIds?: string },
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/role/authUser/cancelAll", {
    method: "PUT",

    params: data,
    ...(options || {}),
  });
}

// /system/role/deptTree/2
export async function getRoleDeptTree(
  roleId: number | string,
  options?: { [key: string]: any }
) {
  return request<API.DeptTreeSelect>("/api/system/role/deptTree/" + roleId, {
    method: "GET",
    ...(options || {}),
  });
}
// PUT /system/role/dataScope
export async function updateRoleDataScope(
  data: {
    roleId: number | string;
    dataScope: string;
    deptCheckStrictly?: boolean;
    deptIds?: number[];
  },
  options?: { [key: string]: any }
) {
  return request<API.ResponseResult>("/api/system/role/dataScope", {
    method: "PUT",
    data,
    ...(options || {}),
  });
}
